﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Zebra.WinFramework
{
    public partial class BaseGridView : UserControl
    {
        public string[] Columns;
        public event DataGridViewCellEventHandler DataRowSelected;

        private object _selectedItem;
        public object SelectedItem
        {
            get { return _selectedItem; }
        }
        public object Datasource { get; set; }

        #region Methods
        public BaseGridView()
        {
            InitializeComponent();
            gvMain.AutoGenerateColumns = false;
        }

        private void ResetRowIndex(object sender)
        {
            for (int i = 0; i < gvMain.Rows.Count; i++)
            {
                // ((sender)dataGridView1.CurrentRow.DataBoundItem);
            }
        }

        public DataGridViewTextBoxColumn AddColumns(string Name)
        {
            DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();
            col.Name = Name;
            col.HeaderText = Name;
            col.HeaderCell.Style.WrapMode = DataGridViewTriState.NotSet;
            col.ToolTipText = Name;
            col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            col.DataPropertyName = Name;
            col.SortMode = DataGridViewColumnSortMode.Automatic;
            return col;
        }
        #endregion

        #region Events

        private void dgvMain_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
                _selectedItem = gvMain.Rows[e.RowIndex].DataBoundItem;

            if (DataRowSelected != null)
                DataRowSelected(_selectedItem, e);
        }

        #endregion
      
        private void dgvMain_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            gvMain.ClearSelection();
        }
    }
}
